﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>



<h3 style="text-align:center">登录页面</h3>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>

    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <style>
        .demo-login-container {
            width: 320px;
            margin: 21px auto 0;
        }

        .demo-login-other .layui-icon {
            position: relative;
            display: inline-block;
            margin: 0 2px;
            top: 2px;
            font-size: 26px;
        }
    </style>
    <form class="layui-form">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="userName" value="" id="userName" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="userPwd" value="" lay-verify="required" id="userPwd" placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>


            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login" lay-on="msg" onclick="GetLogin()">登录</button>
            </div>
            @* <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="login">Login</button>
            </div> *@

        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;

        });
    </script>

</body>
</html>
@* <script src="https://cdnjs.cloudflare.com/ajax/libs/js - jwt/3.0.1/index.js"></script> *@



<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;
        

        // form.on('submit(login)', function (data) {
        //     var userName = $("#userName").val();
        //     var userPwd = $("#userPwd").val();
        //     $.ajax({
        //         url: 'http://localhost:5123/api/UsersInterface/UserLogin',
        //         method: 'post',
        //         data: JSON.stringify({ userName: userName, userPwd: userPwd }),
        //         dataType: "json",
        //         contentType: "application/json",
        //         success: function (response) {
        //             if (response.token) {
        //                 localStorage.setItem('jwt_token', response.token);
        //                 window.location.href = '/Index/IndexZhu';
        //             } else {
        //                 layer.msg(response.message);
        //             }
        //         },
        //         error: function (error) {
        //             layer.msg('An error occurred during login.');
        //         }
        //     });
        //     return false;
        // });



    });
    function GetLogin() {
        var userName = $("#userName").val();
        var userPwd = $("#userPwd").val();

        if (userName != "" && userPwd != "") {
            $.post({
                url: "http://localhost:5123/api/UsersInterface/UserLogin",
                data: JSON.stringify({ userName: userName, userPwd: userPwd }),
                async: false,
                success: function (res) {
                    if (res.code == 0) {
                        var id = res.data.userId
                        console.log(id)
                        
                        layer.msg(res.msg);
                        location.href = "/Index/IndexZhu";
                        // alert(res.msg)
                    }
                    else {
                        layer.msg(res.msg);
                         //alert(res.msg)
                    }
                },
                dataType: "json",
                contentType: "application/json"
            })
        }

    }

</script>